package com.zd.login.dao;

import com.zd.common.utils.DButils;
import com.zd.model.Teacher;
import java.beans.PropertyVetoException;
import java.sql.*;

public class TeacherDao {
    //访问数据库
    public Teacher queryTeacher(String userName,String passWord){
            Teacher teacher=null;
            Connection conn=null;
            PreparedStatement ps=null;
            ResultSet resultSet=null;
        try {
            conn = DButils.getConn();
            String sql="select techid,name,username,password from  t_teacher where username='"+userName+"'  and password='"+passWord+"' ";
            ps = conn.prepareCall(sql);
            resultSet = ps.executeQuery();
            while(resultSet.next()){
                teacher=new Teacher();
                //查到id放到teacher对象中
                teacher.setTechid(resultSet.getInt("techid"));
                teacher.setName(resultSet.getString("name"));
                teacher.setUserName(resultSet.getString("username"));
            }
        } catch (PropertyVetoException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            //关闭连接
            DButils.close(resultSet,ps,conn);
        }
        return  teacher;
    }
}
